<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Report_model extends MY_Model {

	const TABLE = 'report';

	public function add($report_name,$report_email) {
		$data = array(
			'report_name'    => $report_name,
			'report_email'   => $report_email,
		);
		$this->db->insert(self::TABLE, $data);
		return $this->db->insert_id();
	}

	public function delete($report_id) {
		$this->db->where('report_id', $report_id);
		$this->db->delete(self::TABLE);
	}

	public function update($report_id, $report_name, $report_email) {
		$data = array(
               'report_name'  => $report_name,
               'report_email' => $report_email,
        );
		$this->db->where('report_id', $report_id);
		$this->db->update(self::TABLE, $data); 
	}

	public function get_by_id($report_id) {
		$query = $this->db->get_where(self::TABLE,array('report_id' => $report_id));
		return $query->row_array();
	}

	public function get_by_name($report_name) {
		$query = $this->db->get_where(self::TABLE,array('report_name' => $report_name));
		return $query->row_array();
	}

	public function report_lists() {
		$query = $this->db->query('select * from report order by report_id desc');
		return $query->result_array();
	}

	public function report_list() {
		$query = $this->db->query('select report_name from report');
		return $query->result_array();
	}
	
	public function email_list() {
		$query = $this->db->query('select report_email from report');
		return $query->result_array();
	}
}